package com.corpgovernment.common.config;

import com.corpgovernment.common.holder.TenantContextHolder;
import com.ctrip.corp.obt.generic.core.ttl.Ttl;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;

import java.util.concurrent.*;

public class AsyncExecutionThreadPoolConfig extends ThreadPoolExecutor {


    public AsyncExecutionThreadPoolConfig(int corePoolSize,
                                          int maximumPoolSize,
                                          long keepAliveTime,
                                          TimeUnit unit,
                                          BlockingQueue<Runnable> workQueue,
                                          RejectedExecutionHandler handler) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
                Executors.defaultThreadFactory(), handler);
    }

    public AsyncExecutionThreadPoolConfig(int corePoolSize,
                                          int maximumPoolSize,
                                          long keepAliveTime,
                                          TimeUnit unit,
                                          BlockingQueue<Runnable> workQueue,
                                          RejectedExecutionHandler handler, String threadNamePrefix) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
                new CustomizableThreadFactory(threadNamePrefix), handler);
    }

    public AsyncExecutionThreadPoolConfig(int corePoolSize,
                                          int maximumPoolSize,
                                          long keepAliveTime,
                                          TimeUnit unit,
                                          BlockingQueue<Runnable> workQueue,
                                          ThreadFactory threadFactory,
                                          RejectedExecutionHandler handler) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
                threadFactory, handler);
    }

    @Override
    public void execute(Runnable runnable) {
        super.execute(Ttl.wrap(runnable));
    }
}
